It looks like the recent restructuring into an O(N) pass had a regression
(reported in #1695) where deps-of-deps didn't have their build script arguments
propagated upwards. This fixes the caching logic to take into account the
profile as part of the key to ensure that we traverse targets twice if
necessary.
Closes #1695